<?php
namespace MarketServer\Controller;

/**
 * 商品分类控制器
 * 
 * @author SoChishun <14507247@qq.com>
 * @since 1.0.0 <2015-4-2> SoChishun Added.
 */
class ProductCategoryController extends AppbaseController {
    
    /**
     * 检测用户访问权限
     * @since 1.0 <2015-4-2> SoChishun Added.
     */
    public function assert_upr($rule = '') {
        $upr = array(
            'category_list' => true,
            'category_edit' => true,
        );

        $this->user_permission_rules = $upr;
        if ($rule && (!array_key_exists($rule, $upr) || !$upr[$rule])) {
            die('您没有访问权限!');
        }
    }

    /**
     * 获取category_list查询表单数据
     * @return array 包含search和where数组
     * @since 1.0 <2015-4-2> SoChishun Added.
     */
    function category_list_search() {
        $search = I('get.');
        if ($search['keyword']) {
            $where['category_name'] = array('like', '%' . $search['keyword'] . '%');
        }
        return array('search' => $search, 'where' => $where);
    }

    /**
     * category_list操作
     * @since 1.0.0 <2015-4-2> SoChishun Added.
     */
    public function category_list() {
        $this->assert_upr(ACTION_NAME); // 检测访问权限
        $this->base_common_treetable_list('类别', 'ProductCategory');
    }

    /**
     * category_edit操作
     * @param int $id 主键编号
     * @since 1.0 <2015-4-2> SoChishun Added.
     */
    public function category_edit($id = 0) {
        $this->assert_upr(ACTION_NAME); // 检测访问权限
        $this->base_common_treetable_edit('类别', 'ProductCategory', $id);
    }

    /**
     * category_edit_save操作
     * @since 1.0 <2015-4-2> SoChishun Added.
     */
    public function category_edit_save() {
        $this->base_common_treetable_edit_save('ProductCategory',U('ProductCategory/category_list'));
    }

    /**
     * category_delete操作
     * @param int $id 主键编号
     * @since 1.0 <2015-4-2> SoChishun Added.
     */
    public function category_delete($id = 0) {
        $this->base_common_delete($id, 'ProductCategory');
    }
}